package com.eascs.web.o2o.web.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.report.common.entity.BusiOperaForm;
import com.eascs.web.o2o.web.dao.BidmDao;
import com.eascs.web.o2o.web.service.BusiOperaService;
import com.eascs.web.o2o.web.util.StringUtils;

/**
 * @author:hzp
 * @date:2018年3月14日
*/
@Service
public class BusiOperaImpl implements BusiOperaService{

	@Autowired
	BidmDao bidmDao;
	
	@Override
	public PageResult<Object[]> getLoanAfter(BusiOperaForm entity){
		String sql = "select bill_code,province_name,regional_director_name,operator_name,operator_join_date,loan_bank_name,loan_type_name,apply_amount,final_audit_amount,loan_amount,loan_date,end_date,is_continue_loan,loan_id,loan_name,first_loan_date,loan_province,loan_city,loan_county from dm_business_loan_data where 1=1 ";
		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, entity.getPageSize(),entity.getPageIndex());
		StringBuffer querySql = new StringBuffer();
		querySql.append(sql);
		
		if(!StringUtils.isEmpty(entity.getBankLoan())){
			querySql.append(" and loan_bank_code = ?");
			sqlPageQuery.addParam(entity.getBankLoan());
		}
		
		if(!StringUtils.isEmpty(entity.getProvince())){
			querySql.append(" and province_name = ?");
			sqlPageQuery.addParam(entity.getProvince());
		}
		
		if(!StringUtils.isEmpty(entity.getLoanDateStart())){
			querySql.append(" and loan_date >= ?");
			sqlPageQuery.addParam(entity.getLoanDateStart());
		}
		
		if(!StringUtils.isEmpty(entity.getLoanDateEnd())){
			querySql.append(" and loan_date <= ?");
			sqlPageQuery.addParam(entity.getLoanDateEnd());
		}
		sqlPageQuery.setQuerySql(querySql.toString());
		return bidmDao.findDataWithPage(sqlPageQuery);
	}
}
